// pages/home/home.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    movies: [
      {
        title: '影院热映',
        items: [
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          }
        ]
      },
      {
        title: '豆瓣热门',
        items: [
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          }
        ]
      },
      {
        title: '近期热门剧集',
        items: [
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          }
        ]
      },
      {
        title: '哈哈哈',
        items: [
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          },
          {
            title: '我和我的祖国',
            fullStars: 3,
            halfStars: 1,
            grayStars: 1,
            score: '8.0',
            imageUrl: "https://inews.gtimg.com/newsapp_bt/0/14297516724/641"
          }
        ]
      },
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) { 
    this.loadNewData()
  },

  loadNewData() {
    this.loadCity((city)=>{
      console.log(`城市是:${city}`)
      // wx.request({
      //   url: 'https://douban-api.uieee.com/v2/movie/in_theaters',
      //   data: {city: city},
      //   header: {'content-type': 'json'},
      //   success: (res) => {
      //     console.log("dafdsafd",res)
      //   },
      //   fail: (error) => {
      //     console.log("dafdsafd",error)
      //   }
      // })
    })
  },

  loadCity: (succes)=> {
    wx.getLocation({
      success(res) {
        wx.request({
          url: 'https://api.map.baidu.com/reverse_geocoding/v3',
          data: {
            output: 'json',
            coordtype: 'wgs84ll',
            ak: '9zTl9xXSCCA8FTnsqQA9Ro8B1mO85v4W',
            location: `${res.latitude},${res.longitude}`
          },
          success(res){
            let city = res.data.result.addressComponent.city
            city = city.substring(0, city.length - 1)
            succes && succes(city)
            wx.db.toast('获取城市成功')
          },
          fail(){
            wx.db.toastError('获取城市失败')
          }
        })
      },
      fail() {
        wx.db.toastError('获取位置失败')
      }
    })
  },

  // 查看更多
  viewmore: function(evt) {
    const index = evt.currentTarget.dataset.index;
    const obj = this.data.movies[index]
    wx.navigateTo({
      url: `/pages/list/list?movie=${JSON.stringify(obj)}`,
    })
  }

})